package cn.foo.factory;

import cn.foo.dao.UserDao;

import java.lang.reflect.InvocationTargetException;

/**
 * @author Frank
 * @date 07-05
 */
public class DaoFactory {
    public static UserDao getUserDao(String type){
        UserDao dao = null;
        //switch (type){
        //    case "mysql":
        //        dao = new UserDaoImpl();
        //        break;
        //    case "oracle":
        //        dao = new UserDaoImpl2();
        //        break;
        //}
        try {
            dao = (UserDao)(Class.forName(type).getDeclaredConstructor().newInstance());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return dao;
    }
}
